package com.xiaoyu.merchant.ui.widget;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.techfansy.bottomDialog.BottomDialog;
import com.techfansy.moreImageSelected.BitmapUtils;
import com.techfansy.moreImageSelected.ImagePicker;
import com.techfansy.moreImageSelected.ui.ImageGridActivity;
import com.techfansy.photo.PhotoSelect;
import com.techfansy.utils.PermissionUtils;
import com.xiaoyu.commonlib.utils.ToastUtil;
import com.xiaoyu.merchant.R;
import com.xiaoyu.merchant.ui.activity.ModificationDataActivity;

import java.io.Serializable;

import static java.lang.System.currentTimeMillis;


/**
 * 规格控件
 * Created by jk on 2018/4/12.
 */

public class NormView extends LinearLayout implements View.OnClickListener {
    private ImageView normImg;//展示图片
    private EditText normEdit;//规格编辑框
    private ImageView normClearImg;//规格清除按钮
    private EditText priceEdit;//价格编辑框
    private ImageView priceClearImg;//价格清除按钮
    private EditText accountEdit;//库存编辑框
    private ImageView accountClearImg;//库存清除按钮

    private Context mContext;

    public NormView(Context context) {
        this(context, null);
    }

    public NormView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NormView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        initView();
    }

    private void initView() {

        LayoutInflater.from(getContext()).inflate(R.layout.item_norm_layout, this, true);
        normImg = findViewById(R.id.norm_show_img);
        normEdit = findViewById(R.id.one_content_edit);
        normClearImg = findViewById(R.id.one_edit_clear_img);
        priceEdit = findViewById(R.id.two_content_edit);
        priceClearImg = findViewById(R.id.two_edit_clear_img);
        accountEdit = findViewById(R.id.three_content_edit);
        accountClearImg = findViewById(R.id.three_edit_clear_img);

        normImg.setOnClickListener(this);
        normClearImg.setOnClickListener(this);
        priceClearImg.setOnClickListener(this);
        accountClearImg.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        if (v == normImg) {//展示图

        } else if (v == normClearImg) {//规格型号清除按钮
            normEdit.getText().clear();
        } else if (v == priceClearImg) {//价格清除按钮
            priceEdit.getText().clear();
        } else if (v == accountClearImg) {//库存清除按钮
            accountEdit.getText().clear();
        }
    }


    /**
     * 获取规格信息字符串
     *
     * @return
     */
    public String getNormInfo() {
        String normInfo = null;
        if (normImg.getDrawable().getCurrent().getConstantState() == getResources().getDrawable(R.mipmap.guige_zhanshitu).getConstantState() || TextUtils.isEmpty(normEdit.getText()) || TextUtils.isEmpty(priceEdit.getText()) || TextUtils.isEmpty(accountEdit.getText())) {
            return null;
        }
        //http://yikabangb.oss-cn-beijing.aliyuncs.com//mmexport1548683750072.jpg^100cm^26^120,
        normInfo = "^" + normEdit.getText().toString() + "^" + priceEdit.getText().toString() + "^" + accountEdit.getText().toString();
        return normInfo;
    }
}
